﻿using FFmpeg.AutoGen;
using FFmpegDecodecVideo.AttributeUsageFolder;
using FFmpegDecodecVideo.FFmpegUlit;
using Microsoft.Graphics.Canvas;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.DirectX;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace FFmpegDecodecVideo
{


    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public unsafe sealed partial class MainWindow : Window
    {

        public MainWindow()
        {
            this.InitializeComponent();

            Init();
        }

        void Init()
        {
            list.ItemsSource = GetPages(typeof(MainWindow));
            list.ItemClick += (s, e) =>
            {
                if(e.ClickedItem is PageInfo info)
                {
                    myFrame.Navigate(info.Page);
                }
            };
        }

        IEnumerable<PageInfo> GetPages(Type type)
        {
            var assembly = type.Assembly;
            var typeInfos = assembly.GetTypes();

            foreach (TypeInfo typeInfo in typeInfos)
            {
                var pia = typeInfo.GetCustomAttribute<PageInfoAttibute>();
                if (pia != null)
                {

                    yield return new PageInfo(typeInfo, pia.Title);
                }
            }
        }

    }

    public class PageInfo
    {
        public Type Page { get; set; }
        public string Title { get; set; }

        public PageInfo(Type page, string title)
        {
            this.Page = page;
            this.Title = title;
        }
    }
}
